import { companies } from '@/services/user';
import { Modal, Toast } from 'antd-mobile';
const operation = Modal.operation;

export default function checkCompany(ifs, dispatch) {
  companies({}).then((res) => {
    if (res?.data && res.data.length > 0) {
      if (ifs) {
        return;
      }

      let btns = res.data.map((it) => ({
        text: it.name,
        onPress: () => {
          localStorage.setItem('companies', JSON.stringify(it));
          dispatch({
            type: 'global/companies',
            payload: it,
          });
        },
      }));
      btns.unshift({
        text: '请选择公司',
        onPress: () => {},
      });
      operation(btns);
    } else {
      Toast.info(
        '您还没有在我司进行业务办理,到个人中心-我的客服进行业务办理',
        3,
      );
    }
  });
}
